package com.ap.core.domain;

import com.ap.core.common.types.InputMessageType;
import com.ap.core.common.types.SystemTypeCode;
import com.ap.core.common.types.ValidationStatus;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

import javax.persistence.*;

/**
 * User: Ranjit.Singh
 */
@Entity
@Table(name = "T_MESSAGE")
@AttributeOverride(name = "id",column = @Column(name = "MSG_ID"))
@TypeDef(name = "id", typeClass = Long.class)
public class ApMessage extends Identifiable<Long> {

    @Column(name = "message_type_code")
    @Enumerated(EnumType.STRING)
    private InputMessageType inputMessageType;

    @Column(name = "SENDER_TYPE_CODE")
    @Enumerated(EnumType.STRING)
    private SystemTypeCode senderTypeCode;

    @Column(name = "SENDER_ID")
    private String senderId;

    @Column(name = "DESTINATION_TYPE_CODE")
    @Enumerated(EnumType.STRING)
    private SystemTypeCode destinationTypeCode;

    @Column(name = "DESTINATION_ID")
    private String destinationId;

    @Column(name = "sender_message_id")
    private String senderMessageId;

    @Column(name = "MESSAGE_CREATION_TMSTMP")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime messageCreationTimeStamp;

    @Column(name = "VALIDATION_STATUS")
    @Enumerated(EnumType.STRING)
    private ValidationStatus validationStatus;

    @Column(name = "VALIDATION_TMSTMP")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime validationTimeStamp;

    @Column(name = "INPUT_REF_ID")
    private Long inputRefId;

    @Column(name = "OUTPUT_REF_ID")
    private Long outputRefId;

    @Column(name = "reconciliation_cycle_id")
    private String  reconciliationCycleId;

    @Column(name = "reconciliation_date")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
    private LocalDate reconciliationDate;

    protected ApMessage(){}

    public ApMessage(String destinationId,
                     InputMessageType inputMessageType,
                     SystemTypeCode destinationTypeCode,
                     Long inputRefId,
                     SystemTypeCode senderTypeCode,
                     String senderId,
                     Long outputRefId,
                     String senderMessageId,
                     LocalDateTime messageCreationTimeStamp,
                     String reconciliationCycleId,
                     LocalDate reconciliationDate
    ) {
        this.destinationId = destinationId;
        this.destinationTypeCode = destinationTypeCode;
        this.inputMessageType = inputMessageType;
        this.inputRefId = inputRefId;
        this.validationStatus = ValidationStatus.VALID;
        this.validationTimeStamp = new LocalDateTime();
        this.senderTypeCode = senderTypeCode;
        this.senderId = senderId;
        this.outputRefId = outputRefId;
        this.senderMessageId = senderMessageId;
        this.messageCreationTimeStamp = messageCreationTimeStamp;
        this.reconciliationCycleId = reconciliationCycleId;
        this.reconciliationDate = reconciliationDate;
    }

    public void setOutputRefId(Long outputRefId) {
        this.outputRefId = outputRefId;
    }

    public void setInputRefId(Long inputRefId) {
        this.inputRefId = inputRefId;
    }

    public String getDestinationId() {
        return destinationId;
    }

    public SystemTypeCode getDestinationTypeCode() {
        return destinationTypeCode;
    }


    public Long getInputRefId() {
        return inputRefId;
    }

    public LocalDateTime getMessageCreationTimeStamp() {
        return messageCreationTimeStamp;
    }

    public Long getOutputRefId() {
        return outputRefId;
    }

    public String getSenderId() {
        return senderId;
    }

    public SystemTypeCode getSenderTypeCode() {
        return senderTypeCode;
    }

    public ValidationStatus getValidationStatus() {
        return validationStatus;
    }

    public InputMessageType getInputMessageType() {
        return inputMessageType;
    }

    public String getReconciliationCycleId() {
        return reconciliationCycleId;
    }

    public LocalDate getReconciliationDate() {
        return reconciliationDate;
    }

    public String getSenderMessageId() {
        return senderMessageId;
    }

    public void setMessageCreationTimeStamp(LocalDateTime messageCreationTimeStamp) {
        this.messageCreationTimeStamp = messageCreationTimeStamp;
    }

    public void setValidationTimeStamp(LocalDateTime validationTimeStamp) {
        this.validationTimeStamp = validationTimeStamp;
    }

    public void setValidationStatus(ValidationStatus validationStatus) {
        this.validationStatus = validationStatus;
    }

    public LocalDateTime getValidationTimeStamp() {
        return validationTimeStamp;
    }


}
